package com.sunny.ynhz.app;

import android.app.Application;
import android.content.Context;
import android.util.Log;

import com.facebook.stetho.Stetho;
import com.sunny.ynhz.ui.MainActivity;
import com.sunny.ynhz.utils.AppManager;
import com.sunny.ynhz.utils.ApplicationUtils;
import com.sunny.ynhz.utils.ForegroundCallbacks;
import com.uphyca.stetho_realm.RealmInspectorModulesProvider;


import cn.jpush.android.api.JPushInterface;
import io.realm.Realm;
import io.rong.calllib.RongCallClient;
import io.rong.imkit.RongIM;
import io.rong.imlib.RongIMClient;


/**
 * Created by Administrator on 2017-3-18.
 */
public class SNNApplication extends Application {
    public static Context mContext;
    public static int type = -1;

    @Override
    public void onCreate() {
        super.onCreate();
        JPushInterface.setDebugMode(true); 	// 设置开启日志,发布时请关闭日志
        JPushInterface.init(this);
        RongIM.init(getApplicationContext(),"mgb7ka1nm4jog");
        ForegroundCallbacks init = ForegroundCallbacks.init(this);
        init.addListener(new ForegroundCallbacks.Listener() {
            @Override
            public void onBecameForeground() {
                MainActivity activity = (MainActivity) AppManager.getInstance().getActivity(MainActivity.class);
                activity.stopServoce();
            }

            @Override
            public void onBecameBackground() {
                MainActivity activity = (MainActivity) AppManager.getInstance().getActivity(MainActivity.class);
                activity.startService();
            }
        });
        ApplicationUtils.init(getApplicationContext());
        Stetho.initialize(//Stetho初始化
                Stetho.newInitializerBuilder(this)
                        .enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
                        .enableWebKitInspector(RealmInspectorModulesProvider.builder(this).build())
                        .build()
        );

        mContext = getApplicationContext();
        Realm.init(this);

    }
    /**
     * 链接到融云服务器
     *
     * @param token
     */
    public static void connect(String token) {

//        RongIM.setServerInfo("http://183.62.245.251:8082", "http://183.62.245.251:8086");
//        RongCallClient.setEngineServerInfo("183.62.245.251:8080", "183.62.245.251:8080");
        RongIM.connect(token, new RongIMClient.ConnectCallback() {
            @Override
            public void onTokenIncorrect() {

            }

            @Override
            public void onSuccess(String userid) {

            }

            @Override
            public void onError(RongIMClient.ErrorCode errorCode) {

            }
        });


    }
    @Override
    public void onTerminate() {
        super.onTerminate();
    }


}
